config: do MaxRtrAdvInterval init at (ra_maxinterval) init time
authorPaul Donald <[email protected]>
Fri, 3 Oct 2025 14:33:57 +0000 (16:33 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Mon, 13 Oct 2025 07:52:46 +0000 (09:52 +0200)
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/225
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/config.c
src/router.c

index 8a7a9c3d8aaf2459d9ccf45727117520ee95b439..7b0b8fa3bb9f1103a3ad916565cf4b5baf72c83c 100644 (file)
@@ -20,6 +20,7 @@
 #include <libubox/vlist.h>
 
 #include "odhcpd.h"
+#include "router.h"
 #include "dhcpv6-pxe.h"
 
 static struct blob_buf b;
@@ -289,8 +290,12 @@ static void set_interface_defaults(struct interface *iface)
        iface->ra_flags = ND_RA_FLAG_OTHER;
        iface->ra_slaac = true;
        iface->ra_maxinterval = 600;
+       /*
+        * RFC4861: MinRtrAdvInterval: Default: 0.33 * MaxRtrAdvInterval If
+        * MaxRtrAdvInterval >= 9 seconds; otherwise, the Default is MaxRtrAdvInterval.
+        */
        iface->ra_mininterval = iface->ra_maxinterval/3;
-       iface->ra_lifetime = -1;
+       iface->ra_lifetime = 3 * iface->ra_maxinterval; /* RFC4861: AdvDefaultLifetime: Default: 3 * MaxRtrAdvInterval */
        iface->ra_dns = true;
        iface->pio_update = false;
 }
index e9b4372d5b4987e7f8f02c535207531f184b0aeb..c352d19ea68e8825598771e377363674fbaf18f8 100644 (file)
@@ -345,16 +345,6 @@ static int calc_adv_interval(struct interface *iface, uint32_t lowest_found_life
        if (*maxival > lowest_found_lifetime)
                *maxival = lowest_found_lifetime;
 
-       if (*maxival > MaxRtrAdvInterval)
-               *maxival = MaxRtrAdvInterval;
-       else if (*maxival < 4)
-               *maxival = 4;
-
-       if (minival < MinRtrAdvInterval)
-               minival = MinRtrAdvInterval;
-       else if (minival > (*maxival * 3)/4)
-               minival = (*maxival >= 9 ? *maxival/3 : *maxival);
-
        odhcpd_urandom(&msecs, sizeof(msecs));
        msecs = (labs(msecs) % ((*maxival != minival) ? (*maxival - minival)*1000 : 500)) +
                        minival*1000;